<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head th:replace="admin/_fragments :: head(~{::title})">
    <title>博文发布</title>
</head>

<body>
    <!--导航-->
    <nav class="ui inverted attached segment m-padding-tb-mini m-shadow-small">
        <div class="ui container"><!--表示一个容器-->
            <div class="ui inverted secondary stackable menu">
                <!--这个stackable使得适应手机端-->
                <h2 class="ui teal header item">管理后台</h2>
                <a href="#" th:href="@{/blogsa}" class="active m-item item m-mobile-hide" ><i class="home icon"></i>博客</a>
                <a href="#" th:href="@{/totype}" class="m-item item m-mobile-hide"><i class="idea icon"></i>分类</a>
                <a href="#" th:href="@{/toTageaka}" class="m-item item m-mobile-hide"><i class="tags icon"></i>标签</a>
                <div class="right m-item m-mobile-hide menu">
                    <div class="ui dropdown item">
                        <div class="text">
                            <img class="ui avatar image" src="https://unsplash.it/100/100?image=1005"> RobinZ
                        </div>
                        <i class="dropdown icon"></i>
                        <div class="menu">
                            <a href="#" th:href="@{/admin/logout}" class="item">注销</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
            <i class="sidebar icon"></i>
        </a>
    </nav>

    <!--发布Or编辑-->
    <div class="ui container">
        <div class="ui teal inverted attached pointing menu">
            <a href="#" th:href="@{/admin/blogs/input}" class="active item">发布</a>
            <a href="#" th:href="@{/admin/blogs}" class="item">列表</a>
        </div>
    </div>
    <!--中间内容-->
    <div class=" m-container-small m-padding-tb-big">
        <div class="ui container"><!--th:object="${blog}" th:action="*{id}==null ? @{/admin/blogs} : @{/admin/blogs/{id}(id=*{id})}-->
            <form id="blog-form" action="#" th:object="${blog}" th:action="${blog}==null ? @{/insertBlog} : @{/blogupdate(id=*{id})}" method="post" class="ui secondary teal form">
                <!--标题-->
                <input type="hidden" name="published">
                <input type="hidden" name="user_id" th:value="${session.user.id}">
                <div class="required field">
                    <div class="ui left labeled input">
                        <div class="ui selection compact teal basic dropdown label"><!---->
                            <input type="hidden" value="原创" name="flag" th:value="${blog?.flag}">
                            <i class="dropdown icon"></i>
                            <div class="default text">原创</div>
                            <div class="menu">
                                <div class="item" data-value="原创">原创</div>
                                <div class="item" data-value="转载">转载</div>
                                <div class="item" data-value="翻译">翻译</div>
                            </div>
                        </div><!--th:value="*{title}"-->
                        <input type="text" name="title" placeholder="标题" th:value="${blog?.title}">
                    </div>
                </div>
                <!--内容-->
                <div class="field">
                    <div id="md-content" style="z-index: 1 !important"><!--th:text="*{content}"-->
                        <textarea name="content"  placeholder="博客内容..." style="display: none" th:text="${blog?.content}"></textarea>
                    </div>
                </div>

                <!--博客描述-->
                <div class="required field">
                    <div id="md-description" style="z-index: 1 !important;"><!--th:text="*{description}"-->
                        <textarea name="description"  placeholder="博客描述..." maxlength="94" th:text="${blog?.description}"></textarea>
                    </div>
                </div>

                <!--分类和标签-->
                <div class="two fields">
                    <div class="field">
                        <div class="ui left labeled action input">
                            <label class="ui compact teal basic label">分类</label>
                            <div class="ui selection fluid dropdown">
                                <!-- type.id 会将id值赋给blog的type对象--><!--th:value="*{type} != null ? *{type.id}"-->
                                <input type="hidden" name="type_id" th:value="${blog?.type_id}">
                                <i class="dropdown icon"></i>
                                <div class="default text">分类</div>
                                <div class="menu">
                                    <div th:each="type : ${typess}" class="item"  th:data-value="${type.id}" th:text="${type.name}">错误日志</div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui left labeled action input">
                            <label class="ui compact teal basic label">标签</label>
                            <div class="ui fluid selection multiple search dropdown"><!--th:value="*{tagIds}"-->
                                <input type="hidden" name="tag_ids" th:value="${blog?.tag_ids}">
                                <i class="dropdown icon"></i>
                                <div class="default text">标签</div>
                                <div class="menu">
                                    <div th:each="tag : ${selectq}" class="item"th:data-value="${tag.id}" th:text="${tag.name}">操作系统</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!--首图-->
                <div class="field">
                    <div class="ui left labeled input">
                        <label class="ui teal basic label">首图</label><!--th:value="*{firstPicture}"-->
                        <input type="text" name="firstPicture" th:value="${blog?.first_picture}"  placeholder="首图引用地址">
                    </div>
                </div>

                <div class="fields">
                    <div class="field">
                        <div class="ui checkbox"><!--th:checked="*{recommend}"-->
                            <input type="checkbox" id="recommend" name="recommend" th:checked="${blog?.recommend eq '1'}"  class="hidden">
                            <label for="recommend"><p style="color:white">推荐</p></label>
                        </div>
                    </div>

                    <div class="field">
                        <div class="ui checkbox"><!--th:checked="*{shareStatement}"-->
                            <input type="checkbox" id="share_statement" name="share_statement" th:checked="${blog?.share_statement eq '1'}"  class="hidden">
                            <label for="share_statement"><p style="color:white">转载声明</p></label>
                        </div>
                    </div>

                    <div class="field">
                        <div class="ui checkbox"><!--th:checked="*{appreciation}"-->
                            <input type="checkbox" id="appreciation" name="appreciation" th:checked="${blog?.appreciation eq '1'}"  class="hidden" >
                            <label for="appreciation"><p style="color:white">赞赏</p></label>
                        </div>
                    </div>
                    <div class="field">
                        <div class="ui checkbox"><!--th:checked="*{commentabled}"-->
                            <input type="checkbox" id="commentabled" name="commentabled" th:checked="${blog?.commentabled eq '1'}"  class="hidden">
                            <label for="commentabled"><p style="color:white">评论</p></label>
                        </div>
                    </div>
                </div>

                <div class="ui error message"></div>

                <div class="ui right aligned container">
                    <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                    <button type="button" id="save-btn" class="ui primary button">保存</button>
                    <button type="button" id="publish-btn" class="ui teal button">发布</button>
                </div>
            </form>
        </div>
    </div>

    <br>
    <br>
    <!--底部脚本元素-->
    <footer class="ui inverted vertical segment m-padding-tb-massive">
        <div class="ui center aligned container">
            <div class="ui inverted divided stackable grid"><!--分成16份-->
                <div class="three wide column">
                    <div class="ui inverted link list">
                        <div class="item">
                            <img src="./static/images/wechat.png" th:src="@{images/wechat.png}" class="ui rounded image" alt="" style="width: 110px">
                        </div>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced ">最新博客</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">用户故事（User Story）</a>
                        <a href="#" class="item">用户故事（User Story）</a>
                        <a href="#" class="item">用户故事（User Story）</a>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced ">联系我</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">Email: 498166439@qq.com</a>
                        <a href="#" class="item">QQ: 498166439</a>
                        <a href="#" class="item">Wechat: robinz1996</a>
                    </div>
                </div>
                <div class="seven wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced ">Blog</h4>
                    <p class="m-text-thin m-text-spaced m-opacity-mini">这是我的个人博客，会分享编程，刷题，思考相关任何内容，希望可以让大家一起WDNMD...</p>
                </div>
            </div>
            <div class="ui inverted section divider"></div>
            <p class="m-text-thin m-text-spaced m-opacity-mini">Copyright @ 2020 - 2021 RobinZ Designed By RobinZ</p>
        </div>
    </footer>

    <th:block th:replace="admin/_fragments :: script"></th:block>

    <script>
        //<!--初始化markdown插件-->
        var contentEditor;

        $(function() {
            contentEditor = editormd("md-content", {
                width   : "100%",
                height  : 640,
                syncScrolling : "single",
                //        path    : "../static/lib/editormd/lib/"
                path    : "/lib/editormd/lib/"
            });
        });

        $('.menu.toggle').click(function() {
            $('.m-item').toggleClass('m-mobile-hide');
        });

        $('.ui.dropdown').dropdown({
            on : 'hover'
        });

        $('#save-btn').click(function () {     //点击保存，修改发布状态为false
            $('[name="published"]').val(false);
            $('#blog-form').submit();
        });

        $('#publish-btn').click(function () {   //点击发布，修改发布状态为true
            $('[name="published"]').val(true);
            $('#blog-form').submit();
        });


        //检验信息是否为空，为空推送错误报告
        $('.ui.form').form({
            fields : {
                title : {
                    identifier : 'title',
                    rules : [{
                        type : 'empty',
                        prompt : '标题：请输入博客标题'
                    }]
                },
                content : {
                    identifier : 'content',
                    rules : [{
                        type : 'empty',
                        prompt : '内容：请输入博客内容'
                    }]
                },
                typeId : {
                    identifier : 'type.id',
                    rules : [{
                        type : 'empty',
                        prompt : '分类：请选择分类'
                    }]
                },

                firstPicture : {
                    identifier: 'firstPicture',
                    rules: [{
                        type : 'empty',
                        prompt: '标题：请输入博客首图'
                    }]
                },

                description : {
                    identifier: 'description',
                    rules: [{
                        type : 'empty',
                        prompt: '标题：请输入博客描述'
                    }]
                }
            }
        });
    </script>
</body>
</html>